#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        int left; left = 0;
        if(nums.size() <=2) return nums.size();
        for(int right = 1; right < nums.size(); ++right){
            if(nums[left] == nums[right]){
                while(right < nums.size()-1 && nums[right]==nums[right+1]) ++right;
            }
            nums[++left] = nums[right];
        }
        return left+1;
    }
};